package coop.bancocredicoop.proyectos.gd.query.documentType;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.classic.Session;
import org.hibernate.Transaction;

import coop.bancocredicoop.proyectos.gd.domain.DocumentType;
import coop.bancocredicoop.proyectos.gd.hibernate.HibernateUtil;

public class FindAllDocumentTypeOrderByName {

	public List<DocumentType> run() throws Exception {

		Session session = HibernateUtil.getSessionFactory().openSession();
		Transaction tx = null;
		List<DocumentType> listResult = null;

		try {
			tx = session.beginTransaction();

			listResult = _run(session);

			tx.commit();
		}
		catch (Exception e) {
			if (tx != null)
				tx.rollback();
			throw e;
		} finally {
			session.close();
		}

		return listResult;

	}

	private List<DocumentType> _run(Session session) throws Exception {

		Query query = session.createQuery("from DocumentType order by name");
		return query.list();

	}

}
